package cn.diancan.interceptor;

import java.util.Iterator;
import java.util.Map;  
import javax.servlet.http.HttpServletRequest; 
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

import cn.diancan.util.RequestUtil;

public class MethodTimeInterceptor extends MethodFilterInterceptor{

	@Override
	protected String doIntercept(ActionInvocation actionInvocation) throws Exception {
		String action=	RequestUtil.getRequestPath(ServletActionContext.getRequest()); 
		long startTime = System.currentTimeMillis();
		actionInvocation.invoke();
		HttpServletRequest  request =ServletActionContext.getRequest();
		Map map = request.getParameterMap();
		Iterator iterator = map.keySet().iterator();
		StringBuffer sb = new StringBuffer();
		while (iterator.hasNext() ) {
		   String key =  (String)iterator.next();
		   String value =request.getParameter(key);
		   sb.append(key+"	:	" +value+"\n");  
		}
		System.out.print(sb.toString()); 
		System.out.println("path		"+action  +"	use :		" + (System.currentTimeMillis() -startTime)+"\n");
		return null;
	}

}
